<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">

<head>
    <meta charset="UTF-8"/>
    <title>首页链接配置</title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <link rel="stylesheet" th:href="@{/css/font.css}"/>
    <link rel="stylesheet" th:href="@{/css/xadmin.css}"/>
    <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a><cite>链接列表</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header" sec:authorize="hasRole('WX_MINI_ADMIN_FIRST_ADD')">
                    <button class="layui-btn" th:data-id="'/wx/mini/admin/first/to/add/'+${wxMiniAppId}" onclick="xadmin.open('添加记录',this.getAttribute('data-id'))"><i class="layui-icon"></i>添加记录</button>
                </div>
                <form></form>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th style="display: none;">id</th>
                            <th style="width: 50px;">顺序</th>
                            <th style="width: 50px;">位置</th>
                            <th style="display: none;">小程序id</th>
                            <th style="width: 90px;">跳转类型</th>
                            <th style="width: 50px;">图片</th>
                            <th>跳转链接</th>
                            <th>appid</th>
                            <th>备注</th>
                            <th sec:authorize="hasRole('WX_MINI_ADMIN_FIRST_AD')">广告</th>
                            <th style="width: 90px;" sec:authorize="hasRole('WX_MINI_ADMIN_FIRST_AD')">添加广告</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="item,itemStat : ${list}">
                            <td th:text="${item.id}" style="display: none;"></td>
                            <td th:text="${item.orderNum}"></td>
                            <td th:if="${item.orderNum==0}">返回按钮</td>
                            <td th:if="${item.orderNum!=0}">Banner链接</td>
                            <td style="display: none;" th:text="${item.wxMiniAppId}"></td>
                            <td th:text="${item.type==0?'小程序内部跳转':'跳转其它小程序'}"></td>
                            <td><img th:src="${item.picUrl}" width="40" height="20" /></td>
                            <td th:text="${item.url}"></td>
                            <td th:text="${item.openid}"></td>
                            <td th:text="${item.remarks}"></td>
                            <td sec:authorize="hasRole('WX_MINI_ADMIN_FIRST_AD')">
                                <button th:each="adItem,adItemStat : ${item.wxAdList}" th:data-id="${adItem.id}" onclick="delAd(this.getAttribute('data-id'))" class="layui-btn layui-btn layui-btn-xs" th:text="${adItem.name}"></button>
                            </td>
                            <td sec:authorize="hasRole('WX_MINI_ADMIN_FIRST_AD')">
                                <select th:data-id="${item.id}" class="firstPage">
                                    <option>添加广告</option>
                                    <option th:value="'adunit-258dba798b3ba204_banner1_1_'+${item.id}">banner1</option>
                                    <option th:value="'adunit-e1a22255d808c252_banner2_1_'+${item.id}">banner2</option>
                                    <option th:value="'adunit-10031aa95ff4b0e6_banner3_1_'+${item.id}">banner3</option>
                                    <option th:value="'adunit-f6450ded5df421a8_相册视频1_2_'+${item.id}">相册视频1</option>
                                </select>
                            </td>
                            <td class="td-manage">
                            	<button th:if="${item.status==0}" sec:authorize="hasRole('WX_MINI_ADMIN_FIRST_UPDATE')" class="layui-btn layui-btn layui-btn-xs" th:data-id="${item.id}" th:onclick="enabledOrDisable(this.getAttribute('data-id'), 1);">启用</button>
                            	<button th:if="${item.status==1}" sec:authorize="hasRole('WX_MINI_ADMIN_FIRST_UPDATE')" class="layui-btn layui-btn layui-btn-xs" th:data-id="${item.id}" th:onclick="enabledOrDisable(this.getAttribute('data-id'), 0);">停用</button>
                                <button sec:authorize="hasRole('WX_MINI_ADMIN_FIRST_UPDATE')" class="layui-btn layui-btn layui-btn-xs" th:onclick="'xadmin.open(\'编辑\',\'/wx/mini/admin/first/to/update/'+${item.id}+'\')'"><i class="layui-icon">&#xe642;</i>编辑</button>
                                <button sec:authorize="hasRole('WX_MINI_ADMIN_FIRST_DELETE')" class="layui-btn layui-btn-danger" th:data-id="${item.id}" onclick="deleteById(this.getAttribute('data-id'))"><i class="layui-icon" ></i>删除</button>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['laydate', 'form'], function() {
        var laydate = layui.laydate;
        var form = layui.form;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });

        form.on('select', function(data){
            var val=data.value;
            var arrays=val.split("_");
            $.post("/wx/mini/admin/first/ad/"+arrays[3]+"/"+arrays[0]+"/"+arrays[1]+"/"+arrays[2],function(data,status){
                location.reload();
            });
        });
    });

    function deleteById(id) {
        layer.confirm("确定删除此记录？",{btn: ['确定', '取消'], title: "提示"},function () {
            $.post("/wx/mini/admin/first/delete/"+id,function(data,status){
                location.reload();
            });
        });
    }

    function delAd(id) {
        layer.confirm("确定删除此广告？",{btn: ['确定', '取消'], title: "提示"},function () {
            $.post("/wx/mini/admin/first/ad/delete/"+id,function(data,status){
                location.reload();
            });
        });
    }
    
    //启用 停用
    function enabledOrDisable(id, status) {
    	$.post("/wx/mini/admin/first/enabledOrDisable/" + id + "/" + status, function(data, status) {
    		console.log("data:" + data + ", status:" + status);
    		location.reload();
    	});
    }
</script>

</html>